import type { TableColumn } from '@/framework/components/core/super-table';
import { getThirdSystem } from '@/modules/system-docking/api/tripartite-system';
import { ref } from 'vue';

export const systemList = ref();
/**
 * columns
 */
export type TableListItem = {
  id;
  sn;
  name;
  manufacturer;
  model;
  systemId;
  refrigerator;
};
export type TableColumnItem = TableColumn<TableListItem>;

export const baseColumns: TableColumnItem[] = [
  {
    type: 'seq',
    title: '序号',
    width: 60,
  },
  {
    title: '设备编号',
    field: 'sn',
  },
  {
    title: '设备名称',
    field: 'name',
  },
  {
    title: '厂家',
    field: 'manufacturer',
  },
  {
    title: '型号',
    field: 'model',
  },
  {
    title: '所属系统',
    field: 'systemId',
    formatter: ({ cellValue }) => {
      return systemList.value?.find((item) => item?.value === cellValue)?.label;
    },
    formItemProps: {
      component: 'Select',
      componentProps: {
        request: async () => {
          const res = await getThirdSystem({
            paging: false,
          });
          return (systemList.value = res.result.data.map((item) => ({
            label: item.name,
            value: item.id,
          })));
        },
      },
    },
  },
  {
    title: '关联冰箱',
    field: 'refrigerator',
    hideInSearch: true,
  },
];
